import setTheme from '@/assets/skin';
import { maccApi, requestHttp } from '@utils/index';

const state = {
  theme: 'NOC', //默认使用NOC风格，有NOC和RUIYI两种风格选择
};
const mutations = {
  SET_THEME(state, payload) {
    state.theme = payload;
    setTheme(payload);
  },
};
const actions = {
  getTheme({ commit }) {
    return new Promise((resolve, reject) => {
      var data = {
        api: maccApi.GET_USER_THEME,
        method: 'GET',
      };
      requestHttp(data)
        .then((res) => {
          if (res && res.code == 0) {
            commit('SET_THEME', res.theme == 'AUTO' ? 'NOC' : res.theme);
            resolve(res);
          } else {
            reject(res);
          }
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
};

const getters = {
  getTheme: (state) => state.theme,
};

export default {
  namespaced: true, //开启命名空间，更好的区分使用stage,防止不同stage模块中的方法重名
  state,
  getters,
  mutations,
  actions,
};
